@<template>
  <div class="top">
    <div class="header flex-four">
      <div class="left">
        <i class="el-icon-s-fold" v-if="change == 0" @click="showHide1"></i>
        <i class="el-icon-s-unfold" v-if="change == 1" @click="showHide2"></i>
        <span>首页</span>
      </div>
      <div class="right flex-four">
        <div class="img">
          <img src="@/assets/logo.png" alt="" />
        </div>

        <!-- 下拉选择 -->
        <div>
          <el-dropdown @command="handleCommand">
            <span class="el-dropdown-link">
              admin<i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="a"> github地址</el-dropdown-item>
              <el-dropdown-item command="b">码云地址</el-dropdown-item>
              <el-dropdown-item command="c">pro付费版地址</el-dropdown-item>
              <el-dropdown-item command="d">plus付费版地址</el-dropdown-item>
              <el-dropdown-item command="e" divided>退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </div>
    </div>

    <div class="tag">
      <el-tag
        :key="index"
        v-for="(item, index) in addRouter"
        :closable="addRouter.length == 1 ? false : true"
        :effect="item.show ? 'dark' : 'plain'"
        :disable-transitions="false"
        @close="handleClose(item, index)"
        @click="goRouter(item)"
      >
        {{ item.name }}
      </el-tag>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      change: 0,
    };
  },
  methods: {
    showHide1: function () {
      this.$store.state.show = true;
      this.change = 1;
    },
    showHide2: function () {
      this.$store.state.show = false;
      this.change = 0;
    },
    handleClose(tag) {
      this.addRouter.splice(this.addRouter.indexOf(tag), 1);
      if (tag.show) {
        let Path =
          this.$store.state.routerData[this.$store.state.routerData.length - 1]
            .path;
        this.$router.push(Path);
      }
    },
    goRouter(item) {
      this.$router.push(item.path);
      this.$store.commit("changeActive", item.path);
    },
    handleCommand(command) {
      // console.log(command);
      if(command == 'e'){
        sessionStorage.clear()
        this.$router.replace('/')
      }
    },
  },
  computed: {
    addRouter: function () {
      return this.$store.state.routerData;
    },
  },
};
</script>

<style scoped lang='less'>
.top {
  padding: 10px 10px;
  background-color: #fff;
  box-shadow: 0px 3px 5px #9f98a7;
  border-radius: 8px;
  .header {
    font-size: 14px;
    color: #606022;
    padding: 10px 0;
    .left {
      span {
        padding-left: 8px;
      }
    }
    .right {
      .img {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        border: 1px solid #000;
        margin-right: 8px;
        img {
          width: 100%;
          height: 100%;
        }
      }
    }
  }
}

.el-dropdown-link {
  cursor: pointer;
  color: #606022;
}
.el-icon-arrow-down {
  font-size: 12px;
}

.el-tag + .el-tag {
  margin-left: 10px;
}
.button-new-tag {
  margin-left: 10px;
  height: 32px;
  line-height: 30px;
  padding-top: 0;
  padding-bottom: 0;
}
.input-new-tag {
  width: 90px;
  margin-left: 10px;
  vertical-align: bottom;
}
</style>